package com.cgx.controller;

import com.cgx.annotation.ResultHandler;
import com.cgx.entity.User.User;
import com.cgx.service.SessionService;
import com.cgx.service.UserService;
import com.cgx.vo.RequestObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author chenguanxin
 * @date 2021-05-12 22:39
 */
@Controller
@CrossOrigin("*")
@RequestMapping("/api/message")
public class MessageApiController {

    @Autowired
    private UserService userService;

    @Autowired
    private SessionService sessionService;

    @ResponseBody
    @ResultHandler
    @RequestMapping("/userList")
    public Object userList(@RequestBody RequestObject requestObject) {
        Map<String, Object> data = requestObject.getData();
        List<String> idList = (List<String>) data.get("idList");
        List<User> userList = userService.getUserListByIdList(idList);
        return userList;
    }

    @ResponseBody
    @ResultHandler
    @RequestMapping("/getSessionList")
    public Object getSessionList(@RequestBody RequestObject requestObject) {
        return sessionService.getSessionList(requestObject.getData());
    }

    @ResponseBody
    @ResultHandler
    @RequestMapping("/getSessionBySessionId")
    public Object getSessionBySessionId(@RequestBody RequestObject requestObject) {
        return sessionService.getSessionInfoBySessionId(requestObject.getData());
    }

    @ResponseBody
    @ResultHandler
    @RequestMapping("/getSessionInfo")
    public Object getSessionInfo(@RequestBody RequestObject requestObject) {
        return sessionService.getSessionInfo(requestObject.getData());
    }

    @ResponseBody
    @ResultHandler
    @RequestMapping("/getMessage")
    public Object getMessage(@RequestBody RequestObject requestObject) {
        return sessionService.getMessage(requestObject.getData());
    }
}
